const path = require("path")
const genTplStr = (input)=>{
	let tplArr = []
	for(let fn in input){
		if(typeof input[fn]==="function")
			tplArr.push(input[fn].toString())
	}
	return tplArr.join("\n")
}

module.exports = function(source){
	let rsource = "return "+source
	let os = new Function(rsource)()
	let _extends 	= os._extends||{key:"Shape",path:"./paint_tool/shape"} 
	let ph = path.resolve(__dirname,'../script')

	delete os._extends
	let mngFnStr 	= genTplStr(os)
	let code = `
		import ${_extends.key} from '${path.join(ph,_extends.path)}'
		export default class ${os.name} extends ${_extends.key}{
			constructor(){
				super()
			}
			${mngFnStr}
		}
	`
	// if(os.name)
	// console.log(code)
	return code
}

